package com.task.servlet;

import com.alibaba.fastjson.JSON;
import com.task.exception.CommonException;
import com.task.util.HttpRequestUtils;
import com.task.util.LogCacheUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "GetLogInfoServlet",urlPatterns = "/getLog")
public class GetLogInfoServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String  collectorName= request.getParameter("collectorName");
        try {
            HttpRequestUtils.responseJSON(JSON.toJSONString(LogCacheUtil.getLogArray(collectorName)),response);
        } catch (CommonException e) {
            e.printStackTrace();
        }


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String  collectorName= request.getParameter("collectorName");
        try {
            HttpRequestUtils.responseJSON(JSON.toJSONString(LogCacheUtil.getLogArray(collectorName)),response);
        } catch (CommonException e) {
            e.printStackTrace();
        }
    }
}
